package feizhu_0541;

/**
 * @author Jimmy Zhan WORKSTATION
 * @date 2023/6/21 10:57
 * 说明： 翻转字符串，过了2k个就翻转前k个
 */

public class Mine {
    public String reverseStr(String s, int k) {
        if (s.length() == 1) return s;

        char[] c = s.toCharArray();
        for (int i = 0; i < c.length; i+=2*k) {
            int left = i;
            int right = Math.min(c.length - 1, left + k - 1);
            while (left < right){
                char temp = c[left];
                c[left] = c[right];
                c[right] = temp;
                left++;
                right--;
            }
        }
        return new String(c);
    }
}
